//
//  YYangWebImageManager.h
//  YYangWebImageManagerProject
//
//  Created by 蓓蕾 on 2021/11/29.
//

#ifndef YYangWebImageManager_h
#define YYangWebImageManager_h

#define YYImageWeakSelf __weak typeof(self) weakSelf = self;

#define YYangImageHost @"https://"

typedef NS_ENUM(NSInteger, YYImageViewCacheType) {
    /**
     * The image wasn't available the SDWebImage caches, but was downloaded from the web.
     */
    YYImageViewCacheTypeNone,
    /**
     * The image was obtained from the disk cache.
     */
    YYImageViewCacheTypeDisk,
    /**
     * The image was obtained from the memory cache.
     */
    YYImageViewCacheTypeMemory
};

typedef NS_OPTIONS(NSUInteger, YYImageViewOptions) {
    /**
     * By default, when a URL fail to be downloaded, the URL is blacklisted so the library won't keep trying.
     * This flag disable this blacklisting.
     */
    YYImageViewRetryFailed = 1 << 0,

    /**
     * By default, image downloads are started during UI interactions, this flags disable this feature,
     * leading to delayed download on UIScrollView deceleration for instance.
     */
    YYImageViewLowPriority = 1 << 1,

    /**
     * This flag disables on-disk caching
     */
    YYImageViewCacheMemoryOnly = 1 << 2,

    /**
     * This flag enables progressive download, the image is displayed progressively during download as a browser would do.
     * By default, the image is only displayed once completely downloaded.
     */
    YYImageViewProgressiveDownload = 1 << 3,

    /**
     * Even if the image is cached, respect the HTTP response cache control, and refresh the image from remote location if needed.
     * The disk caching will be handled by NSURLCache instead of SDWebImage leading to slight performance degradation.
     * This option helps deal with images changing behind the same request URL, e.g. Facebook graph api profile pics.
     * If a cached image is refreshed, the completion block is called once with the cached image and again with the final image.
     *
     * Use this flag only if you can't make your URLs static with embedded cache busting parameter.
     */
    YYImageViewRefreshCached = 1 << 4,

    /**
     * In iOS 4+, continue the download of the image if the app goes to background. This is achieved by asking the system for
     * extra time in background to let the request finish. If the background task expires the operation will be cancelled.
     */
    YYImageViewContinueInBackground = 1 << 5,

    /**
     * Handles cookies stored in NSHTTPCookieStore by setting
     * NSMutableURLRequest.HTTPShouldHandleCookies = YES;
     */
    YYImageViewHandleCookies = 1 << 6,

    /**
     * Enable to allow untrusted SSL certificates.
     * Useful for testing purposes. Use with caution in production.
     */
    YYImageViewAllowInvalidSSLCertificates = 1 << 7,

    /**
     * By default, images are loaded in the order in which they were queued. This flag moves them to
     * the front of the queue.
     */
    YYImageViewHighPriority = 1 << 8,
    
    /**
     * By default, placeholder images are loaded while the image is loading. This flag will delay the loading
     * of the placeholder image until after the image has finished loading.
     */
    YYImageViewDelayPlaceholder = 1 << 9,

    /**
     * We usually don't call transformDownloadedImage delegate method on animated images,
     * as most transformation code would mangle it.
     * Use this flag to transform them anyway.
     */
    YYImageViewTransformAnimatedImage = 1 << 10,
    
    /**
     * By default, image is added to the imageView after download. But in some cases, we want to
     * have the hand before setting the image (apply a filter or add it with cross-fade animation for instance)
     * Use this flag if you want to manually set the image in the completion when success
     */
    YYImageViewAvoidAutoSetImage = 1 << 11
};

typedef void(^YYImageViewCompletionBlock)(UIImage *image, NSError *error, YYImageViewCacheType cacheType, NSURL *imageURL);

typedef void(^YYImageViewDownloaderProgressBlock)(NSInteger receivedSize, NSInteger expectedSize);


#endif /* YYangWebImageManager_h */
